<template>
  <div class="checkInvoice">
    <!-- <iframe class="iframe" frameborder="0" width="100%" src="http://cn.createpdfonline.org/pdffiles/test(20211215094117).pdf" /> -->
    <img v-if="jpgUrl" :src="jpgUrl" alt="">
    <div>
      <el-button v-if="jpgPdf" round @click="download">下载PDF发票</el-button>
    </div>
  </div>
</template>
<script>
export default {
  name: 'CheckInvoice',
  components: {},
  props: {},
  data() {
    return {
      jpgUrl: '',
      jpgPdf: '',
      name: 'pdf'
    }
  },
  created() {
    const { fapiaoJpgUrl, fapiaoPdfUrl } = this.$route.query
    this.jpgUrl = fapiaoJpgUrl
    this.jpgPdf = fapiaoPdfUrl
  },
  methods: {
    download() {
      // fetch(this.jpgPdf, {
      //   method: 'get',
      //   mode: 'cors'
      // })
      //   .then(response => response.blob())
      //   .then(res => {
      //     const downloadUrl = window.URL.createObjectURL(
      //       // new Blob()
      //       new Blob([res], {
      //         type: 'application/pdf'
      //       })
      //     )
      //     const link = document.createElement('a')
      //     link.href = downloadUrl
      //     link.setAttribute('download', this.name)
      //     document.body.appendChild(link)
      //     link.click()
      //     link.remove()
      //   }).catch(err => {
      //     this.$message.error(err.msg)
      //     window.open(this.url)
      //   })
      window.open(this.jpgPdf, '_blank')
    }
  }

}
</script>
<style rel="stylesheet/scss" lang='scss' scoped>
.checkInvoice {
    width: 100%;
    min-height: 100vh;
    padding: 10px 30px;
    border-radius: 5px;
    background-color: #fff;
    text-align: center;
    .iframe{
      width: 100%;
      height: 80vh;
    }
}
</style>
